package com.tepth.vehiclemaintenance.mvp.main;

import com.tepth.vehiclemaintenance.bean.VehicleMaintain;
import com.tepth.vehiclemaintenance.net.ApiModel;
import com.tepth.vehiclemaintenance.net.observer.SimpleDisposableObserver;

import java.util.ArrayList;

/**
 * Created by TMVPHelper on 2017/05/08
 */
public class MainPresenter extends MainContract.Presenter {

    @Override
    void getMainList() {
        mRxManager.add(mModel.getMainList(mView.getAuthKey(), mView.getStartTime(), mView.getEndTime())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<ArrayList<VehicleMaintain>>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        ArrayList<VehicleMaintain> list = (ArrayList<VehicleMaintain>) o;
                        mView.showList(list);
                    }
                }));
    }

    @Override
    void getNotFinishList() {
        mRxManager.add(mModel.getNotFinishList(mView.getAuthKey(), mView.getStartTime(), mView.getEndTime())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<ArrayList<String>>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        ArrayList<String> list = (ArrayList<String>) o;
                        mView.showNotFinishWorkDates(list);
                    }
                }));
    }

    @Override
    void startWork() {
        mRxManager.add(mModel.startWork(mView.getAuthKey(),mView.getMaintenanceId())
                .subscribeWith(new SimpleDisposableObserver<ApiModel<String>>(mView) {
                    @Override
                    public void onSucceed(Object o) {
                        String info = (String) o;
                        mView.workSucceed();
                    }
                }));
    }
}